package com.baizhi.utils.apache.lang;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

public class StringUtilsTest {

    @Test
    public void test1() {
        String str = "    ";
        System.out.println("【字符串是否为空串】" + StringUtils.isBlank(str));
        System.out.println("【字符串是否非空串】" + StringUtils.isNotBlank(str));
    }

    @Test
    public void test2() {
        String str = "    ";
        System.out.println("【字符串是否为空】" + StringUtils.isEmpty(str));
        System.out.println("【字符串是否非空】" + StringUtils.isNotEmpty(str));
    }

    /**
     * 手机号脱敏
     */
    @Test
    public void test3() {
        String str = "12345678911";
        // 返回左边的几个字符
        String left = StringUtils.left(str, 3);
        // 返回右边的几个字符
        String right = StringUtils.right(str, 4);
        System.out.println(left + "****" + right);

        // 如果left长度小于7，那么就在右边用*填充
        String padResult = StringUtils.rightPad(left, 7, '*');
        System.out.println(padResult + right);
    }
}
